<%@ page import="mybatis.pojo.Student" %>
<%@ page import="mybatis.services.StudentService" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%--
  Created by IntelliJ IDEA.
  User: Dell
  Date: 2022/7/4
  Time: 14:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>



<%


    request.setCharacterEncoding("utf-8");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String sname = request.getParameter("sname");
    String gender = request.getParameter("gender");
    String tel = request.getParameter("tel");
    String qq = request.getParameter("qq");
    String wechat = request.getParameter("wechat");
    int gradeId = Integer.parseInt(request.getParameter("gradeid"));
    Date enterDate = simpleDateFormat.parse(request.getParameter("enterDate"));

    String city = request.getParameter("city");
    Date birth = simpleDateFormat.parse(request.getParameter("birth"));
    String address = request.getParameter("address");
    String psd = request.getParameter("psd");
    String idCard = request.getParameter("idCard");
    Student student = new Student();
    student.setSname(sname);
    student.setSex(gender);
    student.setTelephone(tel);
    student.setQq(qq);
    student.setWechat(wechat);
    student.setGradeid(gradeId);
    student.setEnterdate(enterDate);
    student.setFromcity(city);
    student.setBirthday(birth);
    student.setAddress(address);
    student.setPass(psd);
    student.setIdcardpic(idCard);
    int add = StudentService.ME.add(student);
    if (add > 0) {
        out.print("修改成功");
    } else {
        out.print("修改失败");
    }
    if(add>0){
        //表单重复提交：1）后退再提交 2）直接刷新
        //重定向，可以解决刷新一下，提交两次的问题
        response.sendRedirect("student.jsp");
        // request.getRequestDispatcher("subject.jsp").forward(request,response);
    }else{
        // out.print("增加失败，可能课程名重复了！");
        request.setAttribute("msg","增加失败，可能课程名重复了！");
        request.getRequestDispatcher("studentAdd.jsp").forward(request,response);
        //response.sendRedirect("subjectAdd.jsp");
    }
%>


</body>
</html>

